package cn.edu.scau.cmi.hexiaoqing.client;


import cn.edu.scau.cmi.hexiaoqing.Adapter.ObjectTransformer;
import cn.edu.scau.cmi.hexiaoqing.Adapter.ClassTransformer;
import cn.edu.scau.cmi.hexiaoqing.Adapter.Target;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class ClassAdapterClient extends Application {
	private int U = 220;

	public int getU() {
		return U;
	}

	public void setU(int u) {
		U = u;
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Target target = new ClassTransformer();
		TextField tf = new TextField();
		Button bt1 = new Button("Use Transformer");
		Button bt2 = new Button("Do Not Use Transformer");
		Button bt3 = new Button("Open The TV");
		bt1.setOnMouseClicked(e -> {
			setU(target.output110V());
		});
		bt2.setOnMouseClicked(e -> {
			setU(target.output220V());
		});
		bt3.setOnMouseClicked(e -> {
			int u = getU();
			ImageView imv = new ImageView();
			Stage st2 = new Stage();
			Image image;
			Pane p = new Pane();
			if (u == 110) {
				image = new Image(AbstractFactoryClient.class.getResourceAsStream("timg1.jpg"));
				imv.setImage(image);
				p.getChildren().add(imv);
				Scene sc2 = new Scene(p, 550, 346);
				st2.setScene(sc2);
				st2.setTitle("TV on the sky");
			} else {
				image = new Image(AbstractFactoryClient.class.getResourceAsStream("timg2.jpg"));
				imv.setImage(image);
				p.getChildren().add(imv);
				Scene sc2 = new Scene(p, 650,365);
				st2.setScene(sc2);
				st2.setTitle("TV on rainbow");
			}
			st2.show();
		});
		GridPane gp = new GridPane();
		gp.setAlignment(Pos.CENTER);
		gp.setHgap(10);
		gp.setVgap(20);
		gp.add(bt1, 0, 0);
		gp.add(bt2, 0, 1);
		gp.add(bt3, 0, 3);
		Scene sc = new Scene(gp, 400, 300);
		Stage st = new Stage();
		st.setScene(sc);
		st.setTitle("Use Transformer Or Not");
		st.show();
	}

	public static void main(String[] args) {
		Application.launch(args);
	}

}
